package com.warm.mini.wework.constant;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Description 事件枚举
 * @Author warmchuang
 * @Date 2022/2/9 16:40
 */
public class WeworkConst {
    /**
     * 企微回调地址
     */
    public final static String WX_OAUTH2_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=#wechat_redirect";
    public final static String AUTH_BACK_URL = "http://47.99.135.243:8080/open/v1/auth/authBack?resource=%s&appCode=%s&targetUrl=%s";

    public static final String WEWORK_URL = "https://qyapi.weixin.qq.com";
    public static final String API_GETTOKEN = "/cgi-bin/gettoken";
    public static final String API_USER_GET = "/cgi-bin/user/get";
    public static final String API_USER_GETUSERINFO = "/cgi-bin/user/getuserinfo";

    /**
     * 主体
     */
    @Getter
    public enum Subject {
        TANZSAY("tanzsay", "wwed8a8fdc9b2d8385","炭治说"),
        ;

        private String resource;
        private String corpId;
        private String name;

        Subject(String resource, String corpId, String name) {
            this.resource = resource;
            this.corpId = corpId;
            this.name = name;
        }

        public static Subject getByName(String resource){
            Optional<Subject> first = Arrays.stream(Subject.values()).filter(enm -> enm.getResource().equals(resource)).findFirst();
            return first.isPresent() ? first.get() : null;
        }
    }

    /**
     * 模块
     */
    @Getter
    public enum Model {
        CONTACT("contact", "通讯录"),
        EXTERNAL_CONTACT("external_contact", "外部联系人")
        ;

        private String value;
        private String text;

        Model(String value, String text) {
            this.value = value;
            this.text = text;
        }

        public static Model getByName(String modelName){
            Optional<Model> first = Arrays.stream(Model.values()).filter(enm -> enm.getValue().equals(modelName)).findFirst();
            return first.isPresent() ? first.get() : null;
        }
    }

    /**
     * 通讯变更事件
     */
    @Getter
    public enum ChangeContactEvent {
        CREATE_USER("create_user", "新增成员事件"),
        UPDATE_USER("update_user", "新增成员事件"),
        DELETE_USER("delete_user", "新增成员事件"),
        ;

        private String value;
        private String text;

        ChangeContactEvent(String value, String text) {
            this.value = value;
            this.text = text;
        }

        public static ChangeContactEvent getByName(String modelName){
            Optional<ChangeContactEvent> first = Arrays.stream(ChangeContactEvent.values()).filter(enm -> enm.getValue().equals(modelName)).findFirst();
            return first.isPresent() ? first.get() : null;
        }
    }

    @Getter
    public enum ChangeExternalContactEvent {
        ADD_EXTERNAL_CONTACT("add_external_contact", "添加企业客户事件"),
        EDIT_EXTERNAL_CONTACT("edit_external_contact", "编辑企业客户事件"),
        ;

        private String value;
        private String text;

        ChangeExternalContactEvent(String value, String text) {
            this.value = value;
            this.text = text;
        }

        public static ChangeExternalContactEvent getByName(String modelName){
            Optional<ChangeExternalContactEvent> first = Arrays.stream(ChangeExternalContactEvent.values()).filter(enm -> enm.getValue().equals(modelName)).findFirst();
            return first.isPresent() ? first.get() : null;
        }
    }

}

